<?php get_header(); ?>

<script type="text/javascript" language="javascript">

	$(window).load(function(){
				
	});
	
	$(document).ready(function(){
	
		if ($('#getguid').html() != ""){
			$('.menu').find('a').each(function(){
				if ($(this).attr('href') === $('#getguid').html()){
					$(this).addClass('selected');
					return false;
				}
			});
		}	
			
		
		$('.image-single .hover-image').hover(
			function(){
				$(this).animate({
					'opacity': '.6',
					'filter': 'alpha(opacity = 60)'
				});
			},
			function(){
				$(this).animate({
					'opacity': '0',
					'filter': 'alpha(opacity = 0)'
				});
			}
		);
		
		ffancybox();
		
	});
	
	function ffancybox(){
		$('a#single_image').fancybox({
			'onStart': function(){
				$('.hover-image').remove();
			},
			'onClosed': function(){
				var html = '<div class=\"hover-image\" onclick=\" $(\'a#single_image\').click();\"><div class=\"lupa\"></div></div>';
				$('.image-single').append(html);
				$('.image-single .hover-image').height( $('#single_image img').height() );
				$('.image-single .hover-image').css('margin-top', '-'+$('#single_image img').height()+'px');
				var marginTops = ($('.image-single img').height()-75)/2;
				$('.image-single .lupa').css('top', marginTops+'px' );
				$('.image-single .hover-image').hover(
					function(){
						$(this).animate({
							'opacity': '.6',
							'filter': 'alpha(opacity = 60)'
						});
					},
					function(){
						$(this).animate({
							'opacity': '0',
							'filter': 'alpha(opacity = 0)'
						});
					}
				);
				ffancybox();
			}
		});
	}
	
</script>

<?php if(have_posts()) : ?>
			
	<?php while(have_posts()) : the_post(); ?>
	
		<div class="post" id="post-<?php the_ID(); ?>">
			
			<div class="contentautoheight">
				<div class="titlepage">
					<p><span><?php echo get_the_title() ?></span></p>
				</div>
				<div class="slideimg">
					<div class="autoheight" style="padding-bottom: 0px;">
					
					<?php $date = explode("-", $post->post_date); $day = explode(" ", $post->post_date);
						$month = "";
						switch($date[1]){
							case "01": $month = "Jan"; break;
							case "02": $month = "Feb"; break;
							case "03": $month = "Mar"; break;
							case "04": $month = "Apr"; break;
							case "05": $month = "May"; break;
							case "06": $month = "Jun"; break;
							case "07": $month = "Jul"; break;
							case "08": $month = "Aug"; break;
							case "09": $month = "Sep"; break;
							case "10": $month = "Oct"; break;
							case "11": $month = "Nov"; break;
							case "12": $month = "Dec"; break;
						}
						
					?>
						
						<div class="blog_container">
							<div class="blog_content">
								<div class="blog_title">
									<?php echo $post->post_title; ?>
								</div>
								
								
								<div id="gotimage-<?php the_ID(); ?>" style="display:none; visibility: hidden;"><?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?></div>
								
								<div class="image_date_container">
									<div class="image-single">
										<a id="single_image" href="<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>">
											<img alt="<?php the_title() ?>" src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>"/>
										</a>
										<div class="hover-image" onclick=" $('a#single_image').click();">
											<div class="lupa"></div>
										</div>					
									</div>
									<div class="date_corner">
										<div class="month"><?php echo $month; ?></div>
										<div class="day"><?php echo substr($date[2], 0, 2); ?></div>
									</div>
								</div>
								
								<script type="text/javascript" language="javascript">
									if ($('#gotimage-<?php the_ID(); ?>').html() === "") $('.image-single').remove();
								</script>
								
								<div class="meta">
									<ul>
										<li><?php _e("Posted by"); ?>:&nbsp;<strong><?php echo get_the_author_meta('display_name');?></strong></li>
										<li><?php _e("Date"); ?>:&nbsp;<span><?php echo $day[0]; ?></span></li>
										<li><?php _e("In"); ?>:&nbsp;
											<?php
												$post_categories = wp_get_post_categories($post->ID);
												$cats = array();
												$i = 0;
												$output = "";
												foreach($post_categories as $c){
													$cat = get_category( $c );
													$url = get_category_link($cat->cat_ID);
													$cats[] = array( 'name' => $cat->name, 'url' => $url );
													$i++;
												}
												for ($j = 0; $j < $i; $j++){
													if ($j != $i-1){
														$output .= "<a style='color: #9cb6c3;' href='".$cats[$j]['url']."'>".$cats[$j]['name']."</a>,&nbsp;";
													} else {
														$output .= "<a style='color: #9cb6c3;' href='".$cats[$j]['url']."'>".$cats[$j]['name']."</a>";
													}
												}
												echo $output;
											?>											
										</li>
										<li><div class="balloon"></div><?php echo $post->comment_count; ?> <?php _e("Comments"); ?></li>
									</ul>
								</div>
								
								<div id="getguid" style="color:black; display:none;"><?php //print_r($post);
								
								$querystr = "
									SELECT post_id
									FROM $wpdb->postmeta
									WHERE meta_value = 'template-blog.php'
								";
								
								$pageposts = $wpdb->get_results($querystr, OBJECT);
								$post_id = $pageposts[0]->post_id;
								
								$querystr = "
									SELECT guid
									FROM $wpdb->posts
									WHERE ID = ".$post_id."
								";
								
								$pageposts = $wpdb->get_results($querystr, OBJECT);
								$guid = $pageposts[0]->guid;
								
							

								echo $guid; ?></div>
								
								<div class="blog_text">
									<?php the_content(); wp_link_pages(); ?> 
								</div>
								
								<div class="title_comments"><?php _e("Comments"); ?> (<?php echo $post->comment_count; ?>)</div>
								<div class="comments" style="color: black;">
									<?php comments_template(); ?>
								</div>
								
							</div>
							<div class="bgbottom"></div>
						</div>
						
						
						<!-- SIDEBAR -->
						<div class="blog_sidebar">
														
							<?php get_sidebar(); ?>
						
						</div>
						
						
					</div>
					<div class="hidecorner"></div>
				</div>
			</div>
																							
		</div>
		
	<?php endwhile; ?>
	
	<?php else : ?>
		
		<h2>
			<?php _e("There are currently no posts."); ?>
		</h2>


<?php endif; ?>

<?php get_footer(); ?>